package cn.edu.lcvc.ebuy_23rj2.dao;

import cn.edu.lcvc.ebuy_23rj2.model.Admin;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface AdminDao {
    /**
     * 根据账户名和密码获取符合条件的账户数量1
     * @param username
     * @param password
     * @return
     */
    int countByUsernameAndPassword(@Param("username") String username, @Param("password")String password);

    @Select("select * from admin where username=#{username}")
    Admin getByUsername(String username);

//    @Delete("delete from admin where id=#{id}")
    int deleteById(int id);

//    @Insert("insert into admin(username,password,name,sex,unLocked,createTime) values(#{username},#{password},#{name},#{sex},#{unLocked},now())")
    int save(Admin admin);

    @Select("select count(1) as num from admin where username=#{username}")
    int countByUsername(String username);

    @Select("select * from admin where id=#{id}")
    Admin findById(int id);

    int update(Admin admin);

    @Select("select count(1) as num from admin where username=#{username} and id!=#{id}")
    int countByUsernameAndNotId(@Param("username")String username,@Param("id")Integer id);


    List<Admin> find(@Param("query") Admin query);
}
